namespace Mono.Boost.Graph
{
    using System.Collections.Generic;

    public class Bfs
    {
        public static void calculate_layers<GraphType, LayerType>(GraphType g, LayerType layer, uint beg)
            where GraphType : IGraph
            where LayerType : IDictionary<uint,uint>
        {
            foreach (uint v in g.vertices)
                layer.Remove(v);

            //source
            layer.Add(beg, 0U);
            Queue<uint> q = new Queue<uint>();
            q.Enqueue(beg);

            while (q.Count != 0)
            {
                uint now = q.Dequeue();
                uint lnext = layer[now]+1;
                foreach (EdgeInfo x in g.outgoing(now))
                    if (!layer.ContainsKey(x.v))
                    {
                        layer.Add(x.v, lnext);
                        q.Enqueue(x.v);
                    }
            }
        }
    }
}
